package com.hspedu.method;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/15
 * @time 16:55
 */
@SuppressWarnings("all")
public class ThreadExercise {
    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread();
        Thread thread = new Thread(myThread);
        for (int i = 1; i <= 10; i++) {
            System.out.println("hi " + i);
            Thread.sleep(1000);
            if (i == 5){
                thread.start();
                thread.join();
            }

        }
        System.out.println("主线程结束...");
    }
}

class MyThread implements Runnable{
    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            System.out.println("hello "+i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("子线程结束...");
    }
}
